const http = require('http');

const hostname = '127.0.0.1';
const port = 9875;

const server = http.createServer((req, res) => {
    let exec = require('child_process').exec;
    let cmdStr = 'git pull && npm run prod';
    exec(cmdStr, function (err, stdout, stderr) {
        if ( err ) {
            console.error('err kkk', err)
        } else {
            console.log(stdout);
        }
    });
    console.log('git webhook ' + new Date());
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('git hook success\n');
});

server.listen(port, () => {
    console.log(`Server running at ${port}/`);
});